<template>
  <div>
    <!-- 面包屑   -->
    <div style="margin-bottom: 30px">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>车辆维修记录</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 多条件查询表单-->
    <div style="margin: 10px 0">
      <el-input style="width: 200px" placeholder="请输入车牌号码"
                v-model="search[0]" suffix-icon="el-icon-search"></el-input>
      <el-input style="width: 200px" placeholder="请输入维修工名字"
                v-model="search[1]" suffix-icon="el-icon-user" class="ml-5 mr-5"></el-input>
      <el-date-picker type="date" placeholder="选择入场日期" v-model="search[2]" style="width: 185px;"></el-date-picker>
      <el-date-picker type="date" placeholder="选择出场日期" v-model="search[3]" style="width: 185px;"></el-date-picker>
      <el-button class="ml-5" type="primary" @click="search">查询</el-button>
      <el-button class="ml-5" type="warning" @click="reset">重置</el-button>
    </div>
    <!-- 新增和批量删除组件 -->
    <!--    <div style="margin: 10px 0">-->
    <!--      <el-popconfirm-->
    <!--          confirm-button-text='确定'-->
    <!--          cancel-button-text='再想想'-->
    <!--          icon="el-icon-info"-->
    <!--          icon-color="red"-->
    <!--          title="确定批量删除吗？"-->
    <!--          @confirm="delBatch">-->
    <!--        <el-button type="danger" slot="reference" class="mr-5">批量删除 <i class="el-icon-remove-outline"></i></el-button>-->
    <!--      </el-popconfirm>-->
    <!--    </div>-->
    <!-- 表的主体   -->
    <el-table :data="tableData" border stripe
              @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="40">
      </el-table-column>
      <el-table-column prop="id" label="id">
      </el-table-column>
      <!--      <el-table-column prop="vehicleInfo" label="车辆id">-->
      <!--      </el-table-column>-->
      <el-table-column prop="materialBills" label="材料费用">
      </el-table-column>
      <el-table-column prop="vehicleId" label="维修车辆号牌">
      </el-table-column>
      <el-table-column prop="worktimeBills" label="工时费">
      </el-table-column>
      <el-table-column prop="inTime" label="入场时间">
      </el-table-column>
      <el-table-column prop="outTime" label="出场时间">
      </el-table-column>
      <el-table-column prop="outCheckPeople" label="出场检查人">
      </el-table-column>
      <el-table-column prop="handlePeople" label="经手人">
      </el-table-column>
      <el-table-column prop="reason" label="原因">
      </el-table-column>
      <el-table-column prop="remark" label="备注">
      </el-table-column>
      <el-table-column prop="staffBasicInfo.trueName" label="维修工">
      </el-table-column>
      <el-table-column label="操作" width="" align="center" min-width="100">
        <template slot-scope="scope">
          <el-button type="success" @click="handleEdit(scope.row)" class="mr-5">
            查看详情  <i class="el-icon-search"></i>
          </el-button>
<!--          <el-popconfirm-->
<!--              confirm-button-text='确定'-->
<!--              cancel-button-text='再想想'-->
<!--              icon="el-icon-info"-->
<!--              icon-color="red"-->
<!--              title="确定删除吗？"-->
<!--              @confirm="del(scope.row.vehiclerepairinfoId)">-->
            <!--            <el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i></el-button>-->
<!--          </el-popconfirm>-->
        </template>
      </el-table-column>
    </el-table>
    <!-- 页码导航栏   -->
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[5, 10, 15, 20]"
          :page-size=pageSize
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
      </el-pagination>
    </div>
    <!--    维修记录信息的弹窗    -->
    <el-dialog title="维修记录信息" :visible.sync="dialogFormVisible" width="50%" :close-on-click-modal="false">
      <el-descriptions title="车辆信息" v-if="vehiclerepairinfo.vehicleInfo">
        <el-descriptions-item label="车辆信息">{{ vehiclerepairinfo.vehicleInfo.id}}</el-descriptions-item>
        <el-descriptions-item label="车辆类型">{{ vehiclerepairinfo.vehicleInfo.vehicleStytle }}</el-descriptions-item>
        <el-descriptions-item label="车辆车型">{{vehiclerepairinfo.vehicleInfo.vehicleModel}}</el-descriptions-item>
      </el-descriptions>

<!--      <el-descriptions title="司机信息" v-if="vehiclerepairinfo.vehicleInfo.staffBasicInfo">-->
<!--        <el-descriptions-item label="司机姓名">{{ vehiclerepairinfo.vehicleInfo.staffBasicInfo.trueName}}</el-descriptions-item>-->
<!--        <el-descriptions-item label="司机电话号码">{{ vehiclerepairinfo.vehicleInfo.staffBasicInfo.phoneNumber }}</el-descriptions-item>-->
<!--        <el-descriptions-item label="司机性别">{{vehiclerepairinfo.vehicleInfo.staffBasicInfo.gender}}</el-descriptions-item>-->
<!--      </el-descriptions>-->

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible=false">取 消</el-button>
        <el-button type="primary" @click="save('vehiclerepairinfo')">{{ btnText }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";
import {CodeToText, regionData, TextToCode} from "element-china-area-data";

export default {
  name: "VehicleRepair",
  data() {
    return {
      tableData: [],
      currentPage: 1,
      name: "",
      username: "",
      gender: "",
      pageSize: 5,
      total: 0,
      dialogFormVisible: false,
      btnText: "",
      vehiclerepairinfo: {},
      multipleSelection: [],
      avatarUrl: '',
      idPicUrl: '',
      idPicBackUrl: '',
      areaCodes: [],
      isEditingArea: false,
      options: regionData,
      search: [],
      rules: {
        // name: [
        //   {required: true, message: '请输入姓名', trigger: 'blur'},
        // ],
        // gender: [
        //   {required: true, message: '请选择性别', trigger: 'blur'},
        // ],
        // phone: [
        //   {required: true, message: '请输入电话号码', trigger: 'blur'},
        //   {min: 11, max: 11, message: '请输入长度为11个数字的电话号码', trigger: 'blur'}
        // ],
        // username: [
        //   {required: true, message: '请输入用户名', trigger: 'blur'},
        //   {min: 3, message: '长度在 3 个字符以上', trigger: 'blur'}
        // ],
        // password: [
        //   {required: true, message: '请输入密码', trigger: 'blur'},
        //   {min: 6, message: '长度在 6 个字符以上', trigger: 'blur'}
        // ]
      },
    }
  },
  created() {
    this.load();
  },
  methods: {
    // 分页查询接口
    load() {
      request.get("/vehiclRepair/get",
          {params: {pageNum: this.currentPage, pageSize: this.pageSize}}
      ).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
        this.currentPage = res.data.current
        this.pageSize = res.data.size
      })
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      this.currentPage = pageNum
      this.load()
    },

    handleEdit(row) {
      this.btnText = "修改"
      this.isEditingArea = false
      this.dialogFormVisible = true
      this.vehiclerepairinfo = Object.assign({}, row)
    },
    showAreaEdit() {
      this.isEditingArea = !this.isEditingArea
    },
    // 单个删除
    del(id) {
      request.delete("vehiclerepairinfo/delmore/" + id).then(res => {
        if (res.code === 200) {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
      console.log(id)
    },
    handleSelectionChange(val) {
      // console.log(val)
      this.multipleSelection = val
    },
    // 批量删除接口
    delBatch() {
      //map函数：数组的每个元素都执行一个给定的函数，返回值仍为一个数组
      let ids = this.multipleSelection.map(v => v.vehiclerepairinfoId)
      console.log(ids)
      if (ids.length !== 0) {
        request.delete("vehiclerepairinfo/delmore/" + ids.toString(),).then(res => {
          if (res) {
            this.$message.success("批量删除成功")
            this.load()
          } else {
            this.$message.error("批量删除失败")
          }
        })
      } else {
        this.$message.warning("请选择要删除的数据")
      }
    },
    // 条件查询接口
    // search() {
    //   if (this.gender === " ") {
    //     this.gender = ""
    //   }
    //   request.get("/vehiclerepairinfo/selectbycondition", {
    //     params: {
    //       name: this.name,
    //       username: this.username,
    //       gender: this.gender,
    //     }
    //   }).then(res => {
    //     this.tableData = res
    //     this.total = this.tableData.length
    //     this.currentPage = 0
    //   })
    // },
    reset() {
      this.search = []
      this.load()
    },
    handleAvatarSuccess1(res, file) {//处理头像
      this.avatarUrl = URL.createObjectURL(file.raw);
      this.vehiclerepairinfo.photo = res
    },
    handleAvatarSuccess2(res, file) {//处理身份证正面
      this.idPicUrl = URL.createObjectURL(file.raw);
      this.vehiclerepairinfo.idPicture = res
    },
    handleAvatarSuccess3(res, file) {//处理身份证背面
      this.idPicBackUrl = URL.createObjectURL(file.raw);
      this.vehiclerepairinfo.idPictureBack = res
    },
    beforeAvatarUpload(file) {
      const isJPG_PNG = file.type === 'image/jpeg' || file.type === 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG_PNG) {
        this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG_PNG && isLt2M;
    }
  }
}
</script>

<style scoped>

</style>